<?php if (Request::current()->route() == Route::get('frontend_forum') AND Request::current()->action() == 'section'): ?>
	<div class="padding">
		<h1><a href="<?php echo URL::site(Route::get('frontend_forum')->uri(), TRUE); ?>" title="Форум Nissan Cedric">Форум Nissan Cedric (Ниссан Цедрик)</a></h1>
	</div>
<?php endif; ?>

<div class="padding">
	<table class="forum forum_section">
		<thead>
			<tr class="first">
				<td colspan="5">
					<h2><?php
					if (Request::current()->route() == Route::get('frontend_forum') AND Request::current()->action() == 'section'):
						?><?php echo $section->name; ?><?php
					else:
						?><a href="<?php echo URL::site(Route::get('frontend_forum')->uri(array(
							'controller' => 'forum',
							'action' => 'section',
							'id' => $section->id,
						))); ?>"><?php echo $section->name; ?></a><?php
					endif; ?></h2>
				</td>
			</tr>
			<tr class="thead">
				<td></td>
				<td class="wsn">Форум</td>
				<td class="wsn">Темы</td>
				<td class="wsn">Сообщения</td>
				<td class="wsn" style="width: 200px;">Последнее сообщение</td>
			</tr>
		</thead>
		<tbody>
			<?php foreach ($section->cats->order_by('sort', 'ASC')->find_all() as $cat): ?>
			<tr>
				<td class="ico altrow"><?php
					if (Model_Reg::get('user')->id == '' OR $cat->unreaded->where('user_id', '=', Model_Reg::get('user')->id)->count_all() < 1)
						echo '<span class="forum-ico forum-ico-posts-off" title="Нет новых сообщений"></span>';
					else
						echo '<span class="forum-ico forum-ico-posts" title="Есть новые сообщения"></span>';
				?></td>
				<td>
					<span class="title">
							<a href="<?php echo URL::site(Route::get('frontend_forum')->uri(array(
							'controller' => 'forum',
							'action' => 'cat',
							'id' => $cat->id,
						))); ?>" <?php if (Model_Reg::get('user')->id == '' OR $cat->unreaded->where('user_id', '=', Model_Reg::get('user')->id)->count_all() < 1) echo 'class="fclight"'; ?>><?php echo $cat->name; ?></a>
						<br />
					</span>
					<span class="desc"><?php echo $cat->shortdesc; ?></span>
				</td>
				<td class="altrow w16px tac fssmall"><?php echo intval($cat->topics->count_all()); ?></td>
				<td class="altrow altrow2 w16px tac fssmall"><?php echo intval($cat->messages->count_all()); ?></td>
				<td class="tal w16px fsmini"><?php
					$lastmessage = $cat->messages->order_by('date', 'DESC')->limit(1)->find();
					if (isset($lastmessage->id)):
						echo '<span>'.date('d.m.Y в H:i', $lastmessage->date).'<br /></span>';
						echo '<span><a href="'.URL::site(Route::get('frontend_forum')->uri(array(
							'action' => 'goto',
							'id' => $lastmessage->id,
						))).'">'.$lastmessage->topic->name.'</a><br /></span>';
						echo '<span>от <a class="fcnormal" href="'.URL::site(Route::get('frontend_user')->uri(array(
							'action' => 'view',
							'id' => $lastmessage->user->id,
						))).'">'.Model_User::nickname($lastmessage->user).'</a></span>';
					else:
						echo '<span>&mdash;</span>';
					endif;
				?></td>
			</tr>
			<?php endforeach; ?>
		</tbody>
	</table>
</div>